//无支付功能,无购车版本,影响页面aboutMe.html,index.html,pcProduct.html,product.html  按照注释两套内容切换即可
var ls=window.sessionStorage;
var wxappid = "wx1e4c71ccbc89282a";
var h = 'https';
// var domain = "api.lightkitch.com";
var domain = "mall.zmmmzyy.cn";

var ishttps = 'https:' == document.location.protocol ? true: false;

if(ishttps){

    h = 'https';

}else{

    h = 'http';

}

//色调属性(red,orange)
var _styleColor = "orange";
var  defaults={
    "version":"1.1",
    "from":'h5',
    "accept_language":"English",
    "types":"post",
    "url":h+"://"+domain+"/",
    "dataType":"json",
    "datas":{},
    "debug":false,
    "ipUrl":h+"://"+domain+"/",
    "imgWebIpUrl":h+"://"+domain+"/phoneh5_zh",//测试环境,
    "collectpageUrl":h+"://"+domain+"/cmsconsole/mobile/",
    "resUrl":h+"://"+domain+"/res",
    "_styleColorUrl":h+"://"+domain+"/phoneh5_zh/css/color-"+_styleColor+".css",
    "cache":{"mall_category":60000}
}
var store_title = "test商城";
var share_title = "商城测试环境";
var share_img = h+"://"+domain+"/phoneh5_zh/image/logo11.jpg";
var share_summary = "“test商城”是以运营**业务为主的大型B2C电子商务网站，*******“test商城”的知名度，以“全新体验、全新享受、全心服务”为经营理念，打造最具影响力的文化消费网络平台。";


var _im_path='47.93.1.27';     //测试环境
var oss_url="http://keyshasha.oss-cn-zhangjiakou.aliyuncs.com/";
var _163_im_appkey = 'e7382694a60dc94ecc2550f20d6612de';   //正式环境
//h5支付开关 start
var h5_pay_flag = false,danwei="¥";

var app_android_version="1.0.0";
var app_ios_version="1.0.0";

//分享页面app下载路径
var iOSApp_appUrl="https://apps.apple.com/cn/app/%E5%82%BB%E5%82%BB%E5%93%81%E7%89%8C%E7%BD%91/id1493179534";
var Android_appUrl="https://a.app.qq.com/o/simple.jsp?pkgname=com.shashazengpin.mall&fromcase=40002";
//商城类型B2C、B2B2C
var malltype="B2C";
//三级分销隐藏开关（1 开启  0 隐藏）
var three_distribution = 1;

//检测是否开启积分商城
function showJfStore(){
    var _integralStoreSwitch=ls.getItem("integralStoreSwitch");
    if(isDefine(_integralStoreSwitch) && _integralStoreSwitch=="true"){
        $("#jf_store").show();
    }else{
        $("#jf_store").hide();
    }
}

//------判断终端------
var u = navigator.userAgent, app = navigator.appVersion;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端


//加载风格=========开始=========
var _styleUrl = defaults._styleColorUrl;
var _styleHead = document.getElementsByTagName('HEAD').item(0);
var _styleLink = document.createElement("link");
_styleLink.rel = "stylesheet";
_styleLink.type = "text/css";
_styleLink.href = _styleUrl;
_styleHead.appendChild(_styleLink);
//加载风格=========结束===========

$(document).ready(function() {
    //检测是否开启积分商城
    // showJfStore();
    // getAdvertByCode();//根据编码获取广告
    // initlogo();
    // if(malltype!="B2B2C"){
    //     $(".b2b2cclass").show();
    // }
})

function pb_h5_pay(url){
    if(navigator.onLine){
        if(url != null && "" != url && url != undefined){
            if(h5_pay_flag){
                layer.msg('此功能暂未开放，敬请期待');
                return;
            }else{
                window.location.href = url;
            }
        }else{
            if(h5_pay_flag){
                layer.msg('此功能暂未开放，敬请期待');
                return true;
            }else{
                return false;
            }
        }
    }else{
        layer.msg('网络异常请检查网络')
    }
    return 	true
}
//h5支付开关  end
function getParam(){
    var url = window.location.search.substr(1);
    // console.log(url);
    var obj = {};
    if(!url) return false;

    var arr = url.split("&");
    // console.log(arr);
    for(var i = 0,len = arr.length; i<len; i++){
        var params = arr[i].split("=");
        // console.log(params);
        obj[params[0]] = decodeURI(params[1]);
    }
    // console.log(obj);
    return obj;
}
/**
 * 判断是否是空
 * @param value
 */
function isDefine(value){
    if(value == null || value == "" || value == "undefined" || value == undefined || value == "null" || value == "(null)" || value == 'NULL' || typeof(value) == 'undefined'){
        return false;
    }
    else{
        value = value+"";
        value = value.replace(/\s/g,"");
        if(value == ""){
            return false;
        }
        return true;
    }
}


//app专用开始
function initWebViewJavascriptBridge(callback) {
    if (window.WebViewJavascriptBridge) {
        callback(WebViewJavascriptBridge)
    } else {
        document.addEventListener(
            'WebViewJavascriptBridgeReady'
            , function() {
                callback(WebViewJavascriptBridge)
            },false);
    }
}

//JSBridge初始化：固定代码
initWebViewJavascriptBridge(function(bridge) {
    bridge.init();
    //声明Native 调用 JS 的方法
    /*bridge.registerHandler("functionInJs", function(data, responseCallback) {
		alert("native参数"+data);
        document.getElementById("show").innerHTML = (data);
        var responseData = "从JS传来的数据";
        responseCallback(responseData);
    });*/
})

/*function getH5Token(){
    if(isInApp()){
        alert("开始调用native");
        window.WebViewJavascriptBridge.callHandler(
            'getJSToken'
            , {'userId': 'test'}
            , function(responseData) {
                alert("appcallback"+responseData+"appcallback");
                return responseData;
            }
        );
    }else{
        return "";
    }
}*/

// 创建Base64对象
var Base64 = {
    _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
    encode: function(e) {
        var t = "";
        var n, r, i, s, o, u, a;
        var f = 0;
        e = Base64._utf8_encode(e);
        while (f < e.length) {
            n = e.charCodeAt(f++);
            r = e.charCodeAt(f++);
            i = e.charCodeAt(f++);
            s = n >> 2;
            o = (n & 3) << 4 | r >> 4;
            u = (r & 15) << 2 | i >> 6;
            a = i & 63;
            if (isNaN(r)) {
                u = a = 64
            } else if (isNaN(i)) {
                a = 64
            }
            t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a)
        }
        return t
    },
    decode: function(e) {
        var t = "";
        var n, r, i;
        var s, o, u, a;
        var f = 0;
        e=e.replace(/[^A-Za-z0-9+/=]/g,"");
        while (f < e.length) {
            s = this._keyStr.indexOf(e.charAt(f++));
            o = this._keyStr.indexOf(e.charAt(f++));
            u = this._keyStr.indexOf(e.charAt(f++));
            a = this._keyStr.indexOf(e.charAt(f++));
            n = s << 2 | o >> 4;
            r = (o & 15) << 4 | u >> 2;
            i = (u & 3) << 6 | a;
            t = t + String.fromCharCode(n);
            if (u != 64) {
                t = t + String.fromCharCode(r)
            }
            if (a != 64) {
                t = t + String.fromCharCode(i)
            }
        }
        t = Base64._utf8_decode(t);
        return t
    },
    _utf8_encode: function(e) {
        e = e.replace(/rn/g, "n");
        var t = "";
        for (var n = 0; n < e.length; n++) {
            var r = e.charCodeAt(n);
            if (r < 128) {
                t += String.fromCharCode(r)
            } else if (r > 127 && r < 2048) {
                t += String.fromCharCode(r >> 6 | 192);
                t += String.fromCharCode(r & 63 | 128)
            } else {
                t += String.fromCharCode(r >> 12 | 224);
                t += String.fromCharCode(r >> 6 & 63 | 128);
                t += String.fromCharCode(r & 63 | 128)
            }
        }
        return t
    },
    _utf8_decode: function(e) {
        var t = "";
        var n = 0;
        var r = c1 = c2 = 0;
        while (n < e.length) {
            r = e.charCodeAt(n);
            if (r < 128) {
                t += String.fromCharCode(r);
                n++
            } else if (r > 191 && r < 224) {
                c2 = e.charCodeAt(n + 1);
                t += String.fromCharCode((r & 31) << 6 | c2 & 63);
                n += 2
            } else {
                c2 = e.charCodeAt(n + 1);
                c3 = e.charCodeAt(n + 2);
                t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
                n += 3
            }
        }
        return t
    }
}

var _h5token=ls.getItem("h5token");
var _h5tokenp=getParam().h5token;
if(isDefine(_h5tokenp)){
    _h5token=_h5tokenp;
    ls.setItem("h5token",_h5token)
}

//对userToken 做保存处理============开始
var _userToken = getLocalStorageValue("userToken");
var _userTokenBak=getParam().userToken;
var _userIdBak=getParam().userId;
if(isDefine(_userTokenBak)){
    _userToken=_userTokenBak;
    setLocalStorageValue("userToken",_userToken);
}

if(isDefine(_userIdBak)){
    ls.setItem("userId",_userIdBak)
    setLocalStorageValue("autoLogin",_userIdBak);

}
//对userToken 做保存处理============结束

//对appToken 做保存处理============开始
var _appToken = getLocalStorageValue("appToken");
var _appTokenBak=getParam().appToken;
if(isDefine(_appTokenBak)){
    _appToken=_appTokenBak;
    setLocalStorageValue("appToken",_appToken);
    setLocalStorageValue("userToken",_appToken);

    var app_user_id = getLocalStorageValue("autoLogin");
    if(!isDefine(app_user_id)){
        if(isDefine(_appToken)){
            var _u_token = Base64.decode(_appToken.split('.')[1]);
            var _v_user_id = _u_token.split(",")[1].split(":")[1].replace('"','').replace('"','');
            ls.setItem("userId",_v_user_id)
            setLocalStorageValue("autoLogin",_v_user_id);
        }
    }
}
/*var _appToken = getLocalStorageValue("appToken");
var _appTokenBak=getParam().appToken;
if(isDefine(_appTokenBak)){
    _appToken=_appTokenBak;
    setLocalStorageValue("appToken",_appToken);
    setLocalStorageValue("userToken",_appToken);

    var app_user_id = getLocalStorageValue("autoLogin");
    if(!isDefine(app_user_id)){
        jQuery.ajax({type:'POST',url:defaults.url + 'getUserByToken',data:{"userToken":_appToken},
            success:function(data){
                console.log(data)
                if (isDefine(data.data)){
                    ls.setItem("userId",data.data)
                    setLocalStorageValue("autoLogin",data.data);
                }
            }
        });
    }
}*/

//对appToken 做保存处理============结束

//对来源进行处理  source=and|ios
var _source = getLocalStorageValue("_source");
var _sourceBak=getParam().source;
if (isDefine(_sourceBak)) {
    _source = _sourceBak;
    setLocalStorageValue("_source", _source);
} else {
    if (is_weixn()) {
        deleteLocalStorageValue("_source");
    }
}
//对来源进行处理  结束

function isInApp(){
    //if(isAndroid || isiOS) {
    if (isDefine(getLocalStorageValue("_source"))) {
        return true;
    }
    return false;
    //}
}

/**
 * 处理token出现问题后的逻辑
 * @param data
 */
var register2login_status = false; //因为可能会有多个请求被拦截,只需要有一个弹窗就行,这里是弹窗标识
function tokenError(data) {
    if(data.code =='304' ||data.code =='302' || data.code =='402' || data.code =='305' || data.message =='请重新登录'){
        // delete localStorage["userToken"];
        clearAllCookie();
        gotologin();
    }
    /*if(data.code =='305'){
        layer.msg(data.message,()=>{
            window.location.href="index.html";
        });
    }*/
}
function authorizeMe(){
    gotologin();
}

function gotologin(){
    if(is_weixn()){
        if(getLocalStorageValue("autoLogin")){
            logincc();
        }else{
            layer.confirm("该页面需要授权登录,是否登录?",{
                    btn:['确认','取消'],
                    closeBtn: 0,
                    cancel:function (index,layero){
                        window.location.href="index.html";
                    }
                },function () {
                    logincc();
                },function () {
                    window.location.href="index.html";
                }

            )
        }
    }else if(isInApp()){
        window.location.href="/tj/token/invalid";
    }else{
        layer.confirm('该页面需要授权登录,是否登录?', {
            //按钮
            btn: ['确认','取消'],
            closeBtn: 0,
        }, function(){
            //确认
            var login=2;
            window.location.href="Appsia_login.html?loginBack="+login;
        }, function(){
            //取消
            window.location.href="index.html";
        });
    }
    $('.layui-layer').css({"left":"calc(50% - 130px)"})
    if(is750Width()){
        $('.layui-layer-btn1').css({"font-size":"0.28rem","width":"24%","text-align":"center",'border':0,"color":"#fff!important;","height":"0.64rem","line-height":"0.64rem","padding":"0","margin":"0","background-color":"#f5f5f5"});
        $('.layui-layer-btn0').css({"font-size":"0.28rem","width":"24%","text-align":"center",'border':0,"height":"0.64rem","line-height":"0.64rem","padding":"0 0","margin":"0 .24rem","background-color":"#d7063b"});
    }else{
        $('.layui-layer-btn1').css({"font-size":"0.6rem","width":"24%","text-align":"center",'border':0,"color":"#fff!important;","height":"1.28rem","line-height":"1.28rem","padding":"0","margin":"0","background-color":"#f5f5f5"});
        $('.layui-layer-btn0').css({"font-size":"0.6rem","width":"24%","text-align":"center",'border':0,"height":"1.28rem","line-height":"1.28rem","padding":"0 0","margin":"0 .24rem","background-color":"#d7063b"});
    }
}

function is750Width(){
    var fontsize = document.getElementsByTagName("html")[0].style.fontSize;
    var owidth = parseFloat(fontsize) * 7.5;
    return document.documentElement.clientWidth == Math.round(owidth);
}

function logincc(){
    var url = defaults.url+"weixinApi/mlogin.do";
    var rurl = self.location.href;
    rurl=rurl.replaceAll("&","@@2@@");
    rurl=encodeURIComponent(rurl);
    //rurl = parent.window.location.href;
    //测试环境
    window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+wxappid
        +"&redirect_uri="+url+"&response_type=code&scope=snsapi_userinfo&state="+rurl+"#wechat_redirect";
    //预生产环境
    //parent.window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8186a8797b3bde73"
    //	+"&redirect_uri="+url+"&response_type=code&scope=snsapi_userinfo&state="+rurl+"#wechat_redirect";
    //正式环境
    //parent.window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxcfed93cddd50c254"
    //	+"&redirect_uri="+url+"&response_type=code&scope=snsapi_userinfo&state="+rurl+"#wechat_redirect";
}
/***全部替换***/
String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
    if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
        return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
    } else {
        return this.replace(reallyDo, replaceWith);
    }
}

function loadUserInfo(){
    Datas({
        url:"weixinApi/getInfo.do",
        datas:{},
        async:false,
        success:function(data){
            if (data.status) {
                var currentUser = data.data.currentUser;
                if(currentUser){
                    clearAllCookie();
                    $.session.set("userId",currentUser.id);
                    $.session.set("trueName",currentUser.truename);
                    $.session.set("rebateTotal",currentUser.rebateTotal);
                    $.session.set('salerStoreId',currentUser.storeId);
                    setLocalStorageValue('userToken',data.token);
                    setLocalStorageValue('autoLogin',currentUser.id);
                    if (data.data.pay==true) {
                        $.session.set("pay",1);
                    }
                    //document.location.reload();
                }
            }else{
                gotologin();
            }
        }
    })
}

function Datas(options){
    if(navigator.onLine) {
        if (options && options.validateFn) {
            var s = options.validateFn();
            if (!s) {
                return;
            }
        }

        if (options.debug) {
            console.log(options);
            console.log(defaults);
        }
        if(defaults.cache[options.url]){
            var vstr = window.localStorage.getItem(options.url);
            var v = JSON.parse(vstr);
            if(isDefine(v)){
                if((new Date()).getTime()<v["effective"]){
                    options.success(v.rs);
                    return;
                }else{
                    window.localStorage.removeItem(options.url);
                }
            }
        }
        var tempUrl = defaults.url + options.url;
        var opt=$.extend({},defaults,options);
        opt.url = tempUrl;

        if(isDefine(_h5token)){
            if(isDefine(opt.datas)){
                opt.datas.h5token=_h5token;
            }else{
                opt.datas={"h5token":_h5token};
            }
        }
        if(isDefine(_userToken)){
            if(isDefine(opt.datas)){
                opt.datas.userToken=_userToken;
            }else{
                opt.datas={"userToken":_userToken};
            }
        }

        if(isDefine(_appToken)){
            if(isDefine(opt.datas)){
                opt.datas.userToken=_appToken;
            }else{
                opt.datas={"userToken":_appToken};
            }
        }

        if (defaults.debug) {
            console.log(opt);
        }
        if (opt.async==true) {
            async=true;
        }else{
            async=false;
        }
        opt.success = function(data){
            if(isInApp()){
                if(data.code =='302' || data.code == '304'){
                    //alert("token..............302,304")
                    //token失效或解析失败
                    if(!isDefine(getLocalStorageValue("autoLogin"))){
                        gotologin();
                    }else {
                        window.location.href = "/tj/token/invalid";
                    }
                }else if(data.code == '305'){
                    //没有操作权限
                    if(!isDefine(getLocalStorageValue("autoLogin"))){
                        gotologin();
                    }else {
                        window.location.href = "/tj/token/invalid_2?msg=没有操作权限";
                    }
                }
            }else {
                //处理token出现问题后的逻辑
                tokenError(data);
            }
            if(defaults.cache[options.url]){
                var obj={"effective":(new Date()).getTime()+defaults.cache[options.url],rs:data};
                window.localStorage.setItem(options.url,JSON.stringify(obj));
            }
            options.success(data);
        }
        opt.error = function(XMLHttpRequest,textStatus,errorThrown){
            if(textStatus == 'error'){
                layer.msg(XMLHttpRequest.responseText);
                //alert(XMLHttpRequest);
                //layer.msg('网络异常请检查网络');
            }
        }
        opt.complete = function(XMLHttpRequest,status){ //请求完成后最终执行参数
            /*console.log(status)*/
            if(status=='timeout'){//超时,status还有success,error等值的情况
                ajaxTimeoutTest.abort();
                layer.msg("网络不给力，请点击屏幕重试");
            }
        }
        //console.log(opt.url);
        $.ajax({
            url:opt.url,
            type:'POST',
            async:opt.async,
            cache:false,
            dataType:opt.dataType,
            scriptCharset:'UTF-8',
            data:opt.datas,
            timeOut:6000,
            success: opt.success,
            error:opt.error,
            complete:opt.complete
        })
    }else{
        offlinedeal()
    }

}
function is_weixn(){
    var ua = navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i)=="micromessenger") {
        return true;
    } else {
        return false;
    }
}
var gss_properties = {};
//初始化map_,给map_对象增加方法，使map_像Map
function getMap() {
    var map_ = new Object();
    map_.put = function(key, value) {
        map_[key+'_'] = value;
    };
    map_.get = function(key) {
        return map_[key+'_'];
    };
    map_.remove = function(key) {
        delete map_[key+'_'];
    };
    map_.keyset = function() {
        var ret = "";
        for(var p in map_) {
            if(typeof p == 'string' && p.substring(p.length-1) == "_") {
                ret += ",";
                ret += p.substring(0,p.length-1);
            }
        }
        if(ret == "") {
            return ret.split(",");
        } else {
            return ret.substring(1).split(",");
        }
    };
    return map_;
}

var map = getMap();
function goods_propert(g_id) {
    return map.get(g_id);
}
function initlogo(){
    var _logoUrl=ls.getItem("logoUrl");
    if(!isDefine(_logoUrl)){
        Datas({
            url:"init_logo",
            success:function(data){
                if (data.status) {
                    ls.setItem("logoUrl",data.data);
                    _logoUrl = data.data;
                    $('.mainLogo').css({"background":"url("+_logoUrl+")","background-repeat":"no-repeat",'background-size':"100% 100%"});
                    $('.mainLogos').css({"background":"url("+_logoUrl+")","background-repeat":"no-repeat",'background-size':"100% 100%"});
                    $('.iconbox').css({"background":"url("+_logoUrl+")","background-repeat":"no-repeat",'background-size':"100% 100%"});
                    $('.integral-img').css({"background":"url("+_logoUrl+")","background-repeat":"no-repeat",'background-size':"100% 100%"});
                    $('.titTop').find('span').css({"background":"url("+_logoUrl+")","background-repeat":"no-repeat",'background-size':"100% 100%"});
                    $('.headers').find('span').css({"background":"url("+_logoUrl+")","background-repeat":"no-repeat",'background-size':"100% 100%"});
                    $('.titTop >span').on("click",function(e){
                        window.location.href="index.html";
                    })
                    $('.mainLogo').on("click",function(e){
                        window.location.href="index.html";
                    })
                    $('body').bind('click',function(){
                        $('#chooseMall').css('display','none')
                    })

                    $('.iconbox').on("click",function(){
                        window.location.href="index.html";
                    })
                    $('.integral-img').on("click",function(e){
                        window.location.href="index.html";
                    })

                    $('.headers').find('span').on("click",function(e){
                        window.location.href="index.html";
                    })
                };
            },
            error:function(){
            }
        })
    }else{
        $('.mainLogo').css({"background":"url("+_logoUrl+")","background-repeat":"no-repeat",'background-size':"100% 100%"});
        $('.mainLogos').css({"background":"url("+_logoUrl+")","background-repeat":"no-repeat",'background-size':"100% 100%"});
        $('.iconbox').css({"background":"url("+_logoUrl+")","background-repeat":"no-repeat",'background-size':"100% 100%"});
        $('.integral-img').css({"background":"url("+_logoUrl+")","background-repeat":"no-repeat",'background-size':"100% 100%"});
        $('.titTop').find('span').css({"background":"url("+_logoUrl+")","background-repeat":"no-repeat",'background-size':"100% 100%"});
        $('.headers').find('span').css({"background":"url("+_logoUrl+")","background-repeat":"no-repeat",'background-size':"100% 100%"});
        $('.titTop >span').on("click",function(e){
            window.location.href="index.html";
        })
        $('.mainLogo').on("click",function(e){
            window.location.href="index.html";
        })
        $('body').bind('click',function(){
            $('#chooseMall').css('display','none')
        })

        $('.iconbox').on("click",function(){
            window.location.href="index.html";
        })
        $('.integral-img').on("click",function(e){
            window.location.href="index.html";
        })

        $('.headers').find('span').on("click",function(e){
            window.location.href="index.html";
        })
    }
}



function setSessionStorageValue(key,value){
    var smap = {"zhuanhuankey":value};
    var valstr = JSON.stringify(smap);
    sessionStorage.setItem(key,valstr);
}

function getSessionStorageValue(key){
    var objstr=sessionStorage.getItem(key);
    if(objstr){
        var obj = JSON.parse(objstr);
        return obj.zhuanhuankey;
    }else{
        return objstr;
    }
}

function setLocalStorageValue(key,value){
    var smap = {"zhuanhuankey_local":value};
    var valstr = JSON.stringify(smap);
    localStorage.setItem(key,valstr);
}

function getLocalStorageValue(key){
    var objstr=localStorage.getItem(key);
    if(objstr){
        var obj = JSON.parse(objstr);
        return obj.zhuanhuankey_local;
    }else{
        return objstr;
    }
}
//localStorage删除指定键对应的值
function deleteLocalStorageValue(key){
    localStorage.removeItem(key);
}



function offlinedeal(){
    var str = '';
    if($('body').attr('data-font')==1){

    }else if($('body').attr('data-font')==2){
        if($('body').find('.wrapper1').length==1){
        }else{
            str1='<div style="z-index:10000000000000;position:absolute;left:0;top:0;background:#fff;width:100%;height:100%;"><div class="wrapper1"><div class="right-signal1">网络异常，请检查手机网络</div><div class="active_A name-btn1" onclick="reloadjsp()">刷新</div></div>'
            $('body').append(str1)
        }
    }else{
        str='<div class="wrapper1" style="width:100%;font-size:1rem;margin:0 auto;padding-bottom:1.2rem;"><div class="right-signal1" style="width:100%;height:2rem;margin:0 auto;margin-top:1.86rem;line-height:2rem;text-align:center;font-size:1rem;">网络异常，请检查手机网络</div><div class="active_A name-btn1" onclick="reloadjsp()" style=" margin-top:2.5rem;background:#ff811b;width:6rem;height:1.5rem;line-height:1.5rem;margin:0 auto;text-align:center;border-radius:0.36rem;margin-top:0.48rem;color:white;">刷新</div></div></div>'
    }
    if(str){
        layer.open({
            type : 1,
            //skin: 'layui-layer-lan',
            title: false,
            closeBtn: 0, //不显示关闭按钮
            fix : true,
            shadeClose : true,
            maxmin : false,
            area : [ '100%', '100%' ],
            content : str,
            shift : 2,
            scrollbar : false,
            success : function(layero, index) {
            },
            end : function() {

            },
            cancel : function(cancel) {
            }
        });
    }

}

function reloadjsp(){
    location.reload();
}

//安卓返回按钮键指向函数
function  tjAppGoBack(data,hisUrl){
    switch (data){
        case 'accountBalanceDetail.html' :
            var typeObj=getParam();
            window.location.href="accountManage.html?type="+typeObj.type;
            break;
        case 'accountManage.html' :
            window.location.href="aboutMe.html";
            break;
        case 'accountSafe.html' :
            window.location.href="myAccount.html";
            break;
        case 'alertBoundEmail.html' :
            var Type=getParam().Type;
            if (Type) {
                window.location.href="../phoneSaler/saleMyAccount.html";
            }else{
                window.location.href="myAccount.html";
            }
            break;
        case 'alertBoundMobile.html' :
            var Type=getParam().Type;
            if (Type) {
                window.location.href="../phoneSaler/saleMyAccount.html";
            }else{
                window.location.href="myAccount.html";
            }
            break;
        case 'guestPayBill.html' :
            window.location.href="aboutMe.html";
            break;
        case 'myAccount.html' :
            window.location.href="aboutMe.html";
            break;
        case 'paymentSelect.html' :
            window.location.href="convertComplete.html";
            break;
        case 'signlnWithEmail882.html' :
            var params=getParam(),
                login=params.login,
                loginBack=params.loginBack,
                goods_store=params.goods_store,
                goods_id=params.goods_id;
            if (login) {
                window.location.href="Appsia_login.html?login="+login;
            }else if(loginBack==2){
                window.location.href="Appsia_login.html?loginBack="+loginBack;
            }else if(loginBack==3){
                window.location.href="Appsia_login.html?loginBack="+loginBack+"&goods_store="+goods_store+"&goods_id="+goods_id;
            }else if(loginBack==4){
                window.location.href="Appsia_login.html?loginBack="+loginBack+"&goods_store="+goods_store+"&goods_id="+goods_id;
            }else{
                window.location.href="Appsia_login.html";
            }
            break;
        case 'index.html':
            window.location.href="trade.html";
            break;
        case 'trade.html':
            window.location.href="/finishWebView";
            break;
        default :
            window.location.href=hisUrl;
    }
}
//app头部导航底色采用白色
window.onload=function(){
    if(isInApp()){
        $("header").css("background","#fff").css("border-bottom","1px solid rgb(225,225,230)");
    }
}
//窗口改变rem值改变750的设计稿1rem=50px;调用resizeFontSize函数
function resizeFontSize() {
    var deviceWidth = document.documentElement.clientWidth;
    var deviceHeight = document.documentElement.clientHeight;
    var minLenth = deviceWidth;
    if (deviceWidth > deviceHeight) {};

    if (minLenth >= 750) {
        document.documentElement.style.fontSize = "100px"
    } else {
        document.documentElement.style.fontSize = minLenth / 7.5 + 'px';
    };

};
//检测账户是否被禁
function checkForbid(){
    if(!$.session){
        return;
    }
    if(!getLocalStorageValue("autoLogin")){
        return;
    }
    Datas({
        url:"getUserInfo",
        datas:{

        },
        types:"post",
        success:function(data){
            if(!data.status && data.message=="帐户禁用"){
                $.session.clear();
                layer.msg("您的账户被禁用");
                //location.reload();
                setTimeout(function(){
                    window.location.href="Appsia_login.html";
                },1000)

            }
        },
        error:function(XMLHttpRequest,textStatus,errorThrown){
        }
    })
}

function getImgUrl(imgpath,style){
    if(isEmpty(imgpath))return imgpath;
    if("http"!=imgpath.substring(0,4)){
        imgpath = oss_url+imgpath;
    }
    if(isEmpty(style)){
        style="YS";
    }
    if(imgpath.indexOf("?")!=-1){
        imgpath=imgpath.substring(0,imgpath.indexOf('?'));
    }
    imgpath = imgpath+"?x-oss-process=style/"+style;
    return imgpath;
}
function isEmpty(mixed_var){
    var key;
    if (mixed_var == "" || mixed_var == null ||mixed_var == undefined || typeof mixed_var == 'undefined') {
        return true;
    }

    if (typeof mixed_var == 'object') {
        for (key in mixed_var) {
            return false;
        }
        return true;
    }

    return false;
}

//加载数据 flag 0 不渲染页面 1渲染页面
function getAdvertDataByCode(obj,flag) {
    if(obj.length > 0){
        var array = JSON.stringify(obj);
        Datas({
            url:"buyer/advertListByCode",
            datas:{"code":array},
            success:function(data){
                console.log(data);
                if (data.status) {
                    $.each(data.data,function(k,v){
                        //先更新本地缓存
                        setLocalStorageValue("advert_"+v.ap_encoding,v);
                        if(flag == 1){//单独渲染
                            var advertValue = getLocalStorageValue("advert_"+v.ap_encoding);
                            renderingAdvertHtml($("div[data-adcode='"+v.ap_encoding+"']"),advertValue);
                        }
                    })
                }
            },
            error:function(XMLHttpRequest,textStatus,errorThrown){
                if(textStatus == 'error' && XMLHttpRequest.status == 0){
                    layer.msg(getI18nPageByKey("failToRequest"))
                }else if(textStatus == 'timeout'){
                    layer.msg("网络不给力，请点击屏幕重试");
                }
            }

        })
    }
}
var int=setInterval('clock()', 1000);var num=3;function clock(){num>0 ? num-- : clearInterval(int);$('#time_AP100008').html('倒计时：'+num)}
//获取商品分享推荐人编码
function getReferralGoodsCode(goodsId) {
    var referralGoodsCode = "";
    referralGoodsCode = getLocalStorageValue("referralGoodsCode");
    if(referralGoodsCode == null){
        return "";
    }else{
        var referralGoodsCodeBak = referralGoodsCode.split("_");
        if(referralGoodsCodeBak[0] == goodsId){//是当前分享的商品返回推荐码
            //返回之前先清空改缓存
            deleteLocalStorageValue("referralGoodsCode");
            return referralGoodsCodeBak[1];
        }else{
            return "";
        }
    }
}

function priceFormat2(goods_price){
    var goods_price_list=new Array();
    var price1;
    var price2;
    var unit="";
    var unit1="";
    goods_price_list=goods_price.toString().split("-");
    if(goods_price_list.length==2){
        if(goods_price_list[0]>10000){
            price1=(goods_price_list[0]/10000.00).toFixed(1);
            unit="万";
        }else{
            price1=goods_price_list[0];
        }
        if(goods_price_list[1]>10000){
            price2=(goods_price_list[1]/10000.00).toFixed(1);
            unit1="万";
        }else{
            price2=goods_price_list[1];
            unit1="";
        }
        return price1+unit+"-"+price2+unit1;
    }else{
        if(goods_price>10000){
            price1=(goods_price/10000.00).toFixed(1);
            unit="万";
            return price1+unit;
        }
    }
    return parseFloat(goods_price.toString()).toFixed(2);
}
//判断某个元素是否存在于某个 js 数组中
function in_array(array,str){
    for (var i = 0; i < array.length; i++) {
        if (array[i] == str) {
            return true;
        }
    }
    return false;
}

//获取手机验证码
var countdown=60;
function settime(obj) {
    if (countdown == 0) {
        obj.removeAttribute("disabled");
        obj.value = getI18nPageByKey("sendtxtCode");
        /*"重新发送"*/
        countdown = 60;
        return;
    } else {
        obj.setAttribute("disabled", true);
        obj.value =  "重新发送(" + countdown + ")";
        countdown--;
    }
    setTimeout(function () {
            settime(obj)
        }
        , 1000)
}
function yzm(){
    return "<img src=\""+getVcodeUrl()+"\"/>"
}
function getVcodeUrl(mobile){
    return defaults.url+"/api/authService/getImageVerification?s="+new Date().getTime()+"&phone="+mobile;
}
function changeVcodeImg(mobile) {
    $("#picVcodeImg").attr("src",getVcodeUrl(mobile));
}
function sendMobileCode(obj,_templateId,mobile){
    var myreg = /^1[3456789]\d{9}$/;
    if(!myreg.test(mobile))
    {
        layer.msg("请输入有效的手机号码！");

    }else{
        var str='<div style="padding: 1.4rem 0.512rem 0;height: 2rem">' +
            '<div class="vcode_box" style="font-size: 0;">' +
            '<input class="vcode_input" type="text" maxlength="6" id="picVcodeValue" value="" style="text-indent: 0.4rem;height: 1.4rem;line-height: 1.4rem;border: 1px solid #e5e5e5;border-radius: 0.2rem;width: calc(100% - 4.42rem);margin-right: 0.48rem;"/>' +
            '<img class="vcode_img" id="picVcodeImg" src="'+getVcodeUrl(mobile)+'" onclick="changeVcodeImg('+mobile+')" style="height: 1.4rem;width: 3.84rem;"></img>' +
            '</div>'+
            '</div>';

        layer.open({
            type: 1,
            title: "填写图片验证码",
            closeBtn: 0,
            shadeClose: true,
            skin: 'yourclass',
            area: ['70%','200px'] ,
            btn: ['发送','取消'] ,
            content: str,
            btn2: function(index, layero){
                layer.close(index);
            },
            yes: function(vcodeindex, layero){
                var vcode = $("#picVcodeValue").val();
                if(vcode.length < 4){
                    layer.msg("请仔细填写图片验证码！",{offset: 't'});
                }else{
                    Datas({
                        url:"msg/verifyCode/getMsgCode",
                        datas:{
                            "useType":"validation_phone",
                            "phone":mobile,
                            // "templateId":_templateId,
                            "imageVerifyCode":vcode
                        },
                        success:function(data){
                            // debugger
                            changeVcodeImg(mobile);
                            if(data.code == 200){
                                layer.close(vcodeindex);
                                settime(obj);
                                layer.msg(data.message,{offset: 't'});
                            }else{
                                layer.msg(data.message,{offset: 't'});
                            }
                        }

                    })
                }
                return false;
            }
        });
        $('.layui-layer').css({"border-radius":"6px 6px"});

        if(is750Width()){
            $('.layui-layer-btn1').css({"font-size":"0.28rem","width":"24%","text-align":"center",'border':0,"color":"#fff!important;","height":"0.64rem","line-height":"0.64rem","padding":"0 0","margin":"0 0","background-color":"#f5f5f5"});
            $('.layui-layer-btn0').css({"font-size":"0.28rem","width":"24%","text-align":"center",'border':0,"height":"0.64rem","line-height":"0.64rem","padding":"0 0","margin":"0 .24rem","background-color":"#d7063b","border":"0"});
        }else{
            $('.layui-layer-btn1').css({"font-size":"0.6rem","width":"24%","text-align":"center",'border':0,"color":"#fff!important;","height":"1.28rem","line-height":"1.28rem","padding":"0 0","margin":"0","background-color":"#f5f5f5"});
            $('.layui-layer-btn0').css({"font-size":"0.6rem","width":"24%","text-align":"center",'border':0,"height":"1.28rem","line-height":"1.28rem","padding":"0 0","margin":"0 .24rem","background-color":"#d7063b","border":"0"});
        }
        // $('.layui-layer-btn1').css({"font-size":"0.28rem","width":"24%","text-align":"center",'border':0,"background":"#0060ca!important;","color":"#fff!important;","height":"0.64rem","line-height":"0.64rem","padding":"0 0","margin":"0 0"});
        // $('.layui-layer-btn0').css({"font-size":"0.28rem","width":"24%","text-align":"center",'border':0,"height":"0.64rem","line-height":"0.64rem","padding":"0 0","margin":"0 .24rem"});
    }

}

//手机验证码结束

//清理cookie
function clearAllCookie() {
    $.session.clear();
    var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
    if(keys) {
        for(var i = keys.length; i--;){
            if(keys[i].indexOf("__session") == 0){
                // document.cookie = keys[i] + '=0;domain='+domain+';expires=' + new Date(0).toUTCString()+";path=/";
                document.cookie = keys[i] + '=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
            }
        }
    }
}
/**
 * 动态加载一个js/css文件
 * @param fileName
 * @param fileType
 */
function loadJsCssFile(fileName, fileType){
    if (fileType=="js"){
        var fileRef=document.createElement('script');
        fileRef.setAttribute("type","text/javascript");
        fileRef.setAttribute("src",fileName);
    }else if (fileType=="css"){
        var fileRef=document.createElement("link");
        fileRef.setAttribute("rel","stylesheet");
        fileRef.setAttribute("type","text/css");
        fileRef.setAttribute("href",fileName);
    }
    if (typeof fileRef!="undefined")
        document.getElementsByTagName("head")[0].appendChild(fileRef);
}
/**
 * 移除已经加载过的js/css
 * @param fileName
 * @param fileType
 */
function removeJsCssfile(fileName,fileType){
    var targetElement=(fileType=="js")? "script" :(fileType=="css")? "link" : "none";
    var targetAttr=(fileType=="js")?"src" : (fileType=="css")? "href" :"none";
    var allSuspects=document.getElementsByTagName(targetElement);
    for (var i=allSuspects.length; i>=0;i--){
        if (allSuspects[i] &&allSuspects[i].getAttribute(targetAttr)!=null && allSuspects[i].getAttribute(targetAttr).indexOf(fileName)!=-1)
            allSuspects[i].parentNode.removeChild(allSuspects[i]);
    }
}


